package websocket

import (
	"encoding/json"
	"iron_man_comm/src/common/log"
)

func (s *IotServer) processConnectData(message string) {
	log.Info("start create ros node")
	var data ConnectMessage
	err := json.Unmarshal([]byte(message), &data)
	if err != nil {
		log.Error("ws server process connect data fail, msg: %s", message)
		return
	}
	s.MachineHost = data.Data.Host
	err = s.createRosNode()
	if err != nil {
		log.Error("create ros node fail, err: %s", err.Error())
		s.writeWSConnectResult(false, err.Error())
		return
	}
	go s.listenROSState() //监听ros连接状态

	log.Info("create ros node pass")
	s.writeWSConnectResult(true, "")
}
